<template>
	<view class="container">
		<view class="topbox">
			<view class="text" v-if="infoData">
				服务日期：  {{listData.start_time}}至{{listData.end_time}}（{{listData.cycle_sum}}周期）
			</view>
			<view class="text">您已缴纳的周期个数为：  {{listData.paid_cycle}}个</view>
		</view>
		<view class="paycard1">
			<view class="infolist">
				<view class="text4">计算公式：</view>
				<view class="text4">{{listData.pay_type_desc}}</view>
			</view>
			<view class="infolist">
				<view class="text4">收费金额：</view>
				<view class="text4">{{pay_money}}</view>
			</view>
			<view class="infolist">
				<view class="text4">收费周期：</view>
				<view class="text4">{{listData.pay_cycle}}月/周期</view>
			</view>
			<view class="infolist">
				<view class="text4">请选择缴纳周期费</view>
			</view>
			<view class="infolist2">
				<uni-number-box :min="listData.min_sum" :max="listData.max_sum" :value="changevalue" @change="change"></uni-number-box>
			</view>
			<view class="infolist1">
				<view class="text4">缴费总额：</view>
				<view class="text5">￥{{price}}</view>
			</view>
		</view>
		
		<view class="text2">
			本次最大只可缴费{{listData.max_sum}}个周期
		</view>
		<button type="primary" :style="btn_style" class="btn" @click="btnpay">去支付</button>
	</view>
</template>

<script>
	import uniNumberBox from "../component/uni-number-box/uni-number-box.vue"
	var common = require('../../../utils/common.js');
	var app = getApp();
	var _this;
	const getlifePaylist = () => {
		common.post('HouseApi&a=custom_payment_info', {
			village_id: _this.village_id,
			pigcms_id: _this.pigcms_id,
			bind_id: _this.bind_id,
		}, data => {
			console.log('++++', data)
			_this.listData = data.payment_info;
			_this.payment_name = data.payment_info.payment_name;
			_this.pay_money = data.payment_info.pay_money;
			_this.pay_cycle = data.payment_info.pay_cycle;
			_this.price = data.payment_info.price;
		});
	};
	const getgopayUrl= () => {
		console.log("33333333",_this.payment_name)
		common.post('HouseApi&a=custom_payment_go_pay', {
			village_id: _this.village_id,
			pigcms_id: _this.pigcms_id,
			bind_id: _this.bind_id,
			pay_type: _this.pay_type,
			pay_name: _this.payment_name,
			diy_cycle: _this.changevalue,
			money: _this.price,
		}, data => {
			console.log('++++', data)
			common.parseUrl(data.order_url)
		});
	};
	export default {
		data() {
			return {
				infoData: {},
				listData: [],
				village_id: 0,
				pigcms_id: 0,
				actcolor:'',
				btn_style:'',
				bind_id: 0,
				payment_name:'',
				pay_type: '',
				changevalue: 1,
				pay_money: 0,
				price: 0,
			}
		},
		onShow() {
			// #ifdef H5
				common.hideWxShare()
			// #endif
			// _this.price = _this.pay_money * _this.value
		},
		onLoad(options) {
			_this = this;
			_this.bind_id = options.bind_id;
			_this.pay_type = options.pay_type
			// #ifdef H5
			console.log('准备跳小程序页', _this);
			common.webToMiniapp(_this.route, options, 'redirect')
			// #endif
			
			common.setMainColor(_this, function(config) {
				_this.actcolor = config.config.mobile_head_color
				_this.btn_style = 'background-color: ' + _this.actcolor + ';box-shadow:0px 30rpx 30rpx -30rpx ' + _this.actcolor + ';';
				
				const res = uni.getStorageSync('village_key');
				if (res) {
					_this.village_id = res.village_id;
					_this.pigcms_id = res.pigcms_id;
					_this.village_name = res.village_name;
				};
				
				// if(options.village_id && options.village_id != _this.village_id){
				// 	common.post('HouseApi&a=search_village', {
				// 		village_id: options.village_id
				// 	}, data => {
				// 		_this.village_logo = data.village_logo ? data.village_logo : data.wechat_share_img;
				// 		_this.village_id = options.village_id;
				// 		_this.village_name = options.village_name;
				// 		var res = {
				// 			village_id: _this.village_id,
				// 			village_name: _this.village_name,
				// 			village_logo: _this.village_logo
				// 		};
				// 		if(options.pigcms_id){
				// 			res.pigcms_id = options.pigcms_id;
				// 			_this.pigcms_id = options.pigcms_id;
				// 		}
				// 		uni.setStorageSync('village_key', res);
						
				// 		getlifePaylist();
				// 	});
				// 	return false;
				// }
				
				getlifePaylist();
			});
		},
		methods: {
			btnpay(){
				getgopayUrl()
			},
			change(value){
				console.log("111111111",value)
				_this.changevalue = value
				_this.price = _this.pay_money * _this.changevalue
			},
		},
		components: {
			uniNumberBox
		},
	}
</script>

<style>
	page {
		background: rgb(245, 245, 245);
	}

	.container {
		margin: 0;
		padding: 0;
	}
	.topbox {
		width: 100%;
		height: 289rpx;
		background-color: #2681f3;
	}
	.text {
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 30rpx;
		letter-spacing: 0rpx;
		padding-left: 60rpx ;
		padding-top: 30rpx;
		color: #ffffff;
	}
	.paycard {
		margin: 0 30rpx;
		background-color: #ffffff;
		border-radius: 5rpx;
		margin-top: -150rpx;
		overflow: hidden;
		padding: 50rpx 30rpx;
	}
	
	.paycard1 {
		margin: 0 30rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-top: -130rpx;
		overflow: hidden;
		padding: 30rpx 30rpx;
	}
	.text5 {
		font-size: 32rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 70rpx;
		letter-spacing: 0rpx;
		color: #ff6666;
	}
	.mini-icon {
		width: 50rpx;
		height: 50rpx;
	}
	.icon-img {
		width: 100%;
		height: 100%;
	}
	.infolist {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}
	.infolist2 {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-items: center;
		margin: 20rpx 0rpx;
	}
	.infolist1 {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}
	.text4 {
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 60rpx;
		letter-spacing: -1rpx;
		color: #666666;
	}
	.text2 {
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		color: #999999;
		margin: 30rpx 40rpx 0rpx 40rpx;
	}
	.text3 {
		font-size: 24rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 40rpx;
		letter-spacing: 0rpx;
		color: #999999;
		margin: 0rpx 40rpx 30rpx 40rpx;
	}
	
	.btn {
		font-size: 32rpx;
		font-weight: normal;
		font-stretch: normal;
		line-height: 90rpx;
		letter-spacing: 0px;
		color: #ffffff;
		background-color: #2681f3;
		border-radius: 44rpx;
		margin: 0rpx 100rpx;
		margin-top: 100rpx;
		border: 0rpx;
	}
	
</style>
